package border;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import java.awt.*;

public class MyDemo {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("java-swing");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setSize(400,300);
        jFrame.setVisible(true);


        JPanel jPanel = new JPanel();
        jFrame.setContentPane(jPanel);

        JLabel jLabel1 = new JLabel("1");
        JLabel jLabel2 = new JLabel("2");
        JLabel jLabel3 = new JLabel("3");
        JLabel jLabel4 = new JLabel("4");
        JLabel jLabel5 = new JLabel("5");
        JLabel jLabel6 = new JLabel("6");
        JLabel jLabel7 = new JLabel("7");
        jPanel.add(jLabel1);
        jPanel.add(jLabel2);
        jPanel.add(jLabel3);
        jPanel.add(jLabel4);
        jPanel.add(jLabel5);
        jPanel.add(jLabel6);
        jPanel.add(jLabel7);

        //来源于JComponent,setBorder(Border border)
        //只要是JComponent的子类都可以使用这个方法
        Border border = new LineBorder(Color.BLUE,4 );
        jLabel1.setBorder(border);

        //BorderFactory类中封装了各式的工具方法
        //常用的有createLineBorder()/createMatteBorder()
        //线性边框
        Border border2 = BorderFactory.createLineBorder(Color.BLUE,4);
        jLabel2.setBorder(border2);

        //BorderFactory.createMatteBorder(top,left,right,right,color)
        Border border3 = BorderFactory.createMatteBorder(0,0,4,0,Color.BLUE);
        jLabel3.setBorder(border3);

        //3D立体边框BorderFactory.createRaisedBevelBorder()/BorderFactory.createLoweredBevelBorder()
        Border border4 = BorderFactory.createRaisedBevelBorder();
        jLabel4.setBorder(border4);

        //使用组件的当前背景颜色创建具有“蚀刻”外观的边框，以突出显示和着色。
        Border border5 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
        jLabel5.setBorder(border5);

        //复合边框BorderFactory.createCompoundBorder(外部边框,内部边框)
        Border border6 = BorderFactory.createCompoundBorder(border4,border5);
        jLabel6.setBorder(border6);

        //空白边框
        //Insets对象表示容器的边框。 它指定容器必须在其每个边缘留下的空间。 空间可以是边框，空格或标题。
        Insets insets;
        Border border7 = BorderFactory.createEmptyBorder(6,6,6,6);
        jLabel7.setBorder(border7);
    }
}

